package com.ksvip.next.components.redis.retry;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import com.github.rholder.retry.BlockStrategy;

/**
 * 自旋锁的实现, 不响应线程中断
 */
@Slf4j
@NoArgsConstructor
public class SpinBlockStrategy implements BlockStrategy {

    @Override
    public void block(final long sleepTime) throws InterruptedException {
        final long start = System.currentTimeMillis();
        long end = start;
        log.info("[SpinBlockStrategy]...begin wait.");
        while (end - start <= sleepTime) {
            end = System.currentTimeMillis();
        }
        log.info("[SpinBlockStrategy]...end wait.duration={} ms", end - start);
    }
}
